/*	Table OF Contents
	==========================
	Carousel
	Customs Script [Modal Thumb | List View  Grid View + Add to Wishlist Click Event + Others ]
	Custom Parallax
	Custom Scrollbar
	Custom animated.css effect
	Equal height ( subcategory thumb)
	responsive fix
	*/


    $(function() {
        // add class with selector class equalheight
        $('.thumbnail.equalheight').responsiveEqualHeightGrid();
    });

    $(function() {
        // add class with selector class equalheight
        $('.featuredImgLook2 .inner').responsiveEqualHeightGrid();
    });

    $(function() {
        // add class with selector class equalheight
        $('.featuredImageLook3 .inner').responsiveEqualHeightGrid();
    });

    $(document).ready(function() {
        initCart();
        initCommonFunction();
        sendContact();

        updateCartContent();
        setCarousel();
        showProductModal();

    // collapse according add  active class
    $('.collapseWill').on('click', function(e) {
        //you can list several class names
        $(this).toggleClass("pressed");
        e.preventDefault();
    });

    if ($(window).width() < 989) {
        $('.collapseWill').trigger('click');
    }

    $('.search-box .getFullSearch').on('click', function(e) {
        //you can list several class names
        $('.search-full').addClass("active");
        e.preventDefault();
    });

    $('.search-close').on('click', function(e) {
        //you can list several class names
        $('.search-full').removeClass("active");
        e.preventDefault();
    });

    // List view and Grid view
    $('.list-view').click(function(e) {
        //use a class, since your ID gets mangled
        //add the class to the clicked element
        e.preventDefault();
        $('.item').addClass("list-view");
        $('.add-fav').attr("data-placement",$(this).attr("left"));
    });

    $('.grid-view').click(function(e) {
        //use a class, since your ID gets mangled
        //add the class to the clicked element
        e.preventDefault();
        $('.item').removeClass("list-view");
    });

    // Customs tree menu script 
    $(".dropdown-tree-a").click(function() { //use a class, since your ID gets mangled
        $(this).parent('.dropdown-tree').toggleClass("open-tree active"); //add the class to the clicked element
    });
});

function setCarousel(){
    // NEW ARRIVALS Carousel
    if($("#productslider").length > 0) { $("#productslider").owlCarousel({ items: 4, itemsTablet: [768, 2] }); }
    if($("#banner-carousel").length > 0) { $('#banner-carousel').owlCarousel(); }
    if($(".brand-carousel").length > 0) {
        var owl = $(".brand-carousel");
        owl.owlCarousel({
            //navigation : true, // Show next and prev buttons
            navigation: false,
            pagination: false,
            items: 8,
            itemsTablet: [768, 4],
            itemsMobile: [400, 2]
        });
    }
    // Custom Navigation Events
    $("#nextBrand").click(function() { owl.trigger('owl.next'); });
    $("#prevBrand").click(function() { owl.trigger('owl.prev'); });

    if($("#SimilarProductSlider").length > 0) { $("#SimilarProductSlider").owlCarousel({ navigation: true }); }

    if($("#productShowCase").length > 0) {
        var pshowcase = $("#productShowCase");
        pshowcase.owlCarousel({
            autoPlay : 4000,
            stopOnHover: true,
            navigation: false,
            paginationSpeed: 1000,
            goToFirstSpeed: 2000,
            singleItem: true,
            autoHeight: true
        });
    }

    // Custom Navigation Events
    $("#ps-next").click(function() { pshowcase.trigger('owl.next'); });
    $("#ps-prev").click(function() { pshowcase.trigger('owl.prev'); });

    if($("#imageShowCase").length > 0) {
        var imageShowCase = $("#imageShowCase");
        imageShowCase.owlCarousel({
            autoPlay: 4000,
            stopOnHover: true,
            navigation: false,
            pagination: false,
            paginationSpeed: 1000,
            goToFirstSpeed: 2000,
            singleItem: true,
            autoHeight: true
        });
    }

    // Custom Navigation Events
    $("#ps-next").click(function() { imageShowCase.trigger('owl.next'); });
    $("#ps-prev").click(function() { imageShowCase.trigger('owl.prev'); });
}

function updateCartContent(){
    $.ajax({
        url: $('#cart-content').attr('data-url'),
        type: 'GET',
        cache: false,
        success: function(data){
            $('#cart-content').html(data);
            $('')
        }
    });
}

function showProductModal(){
    $('.quickview a').click(function(e){
        e.preventDefault();
        $('#product-details-modal').modal();
        var ele = $(this);
        $.ajax({
            url: ele.attr('href'),
            type: 'POST',
            data: {'ref': ele.attr('data-cur-url')},
            cache: false,
            success: function(data){
                $('#product-details-modal .modal-content').html(data);
            }
        });
        return false;
    });
}